﻿#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_MusicPlayer.h"
#include"PlaylistManager.h" 
#include"SongList.h"



constexpr int PaddingEdge = 5;

class MusicEngine;
class KuGouMusicManager;
class MusicList;
class SearchList;

class MusicPlayer : public QMainWindow
{
    Q_OBJECT

private:
    enum Direction { UP = 0, DOWN = 1, LEFT, RIGHT, LEFTTOP, LEFTBOTTOM, RIGHTBOTTOM, RIGHTTOP, NONE };
    QPoint m_mousePressedGlobalPoint;  //鼠标的位置
    /*bool m_isLeftPressDown;*/  // 判断左键是否按下
    Direction m_dir;        // 窗口大小改变时，记录改变方向
    bool m_isMoveableArea;
    Ui::MusicPlayerClass ui;
    QPoint m_relativePosPressed_Mouse_Window;  //鼠标与窗口左上角的偏移量
    QRect m_normalWindowGlobalRect;    //最大化前的窗口状态
    // QPixmap m_pix;
    MusicEngine* m_player;
    PlaylistManager& m_listManager;
    SearchList* m_searchList;
    KuGouMusicManager* m_onlineMusicManager;
    MusicList* m_musicList;
#ifdef QT_DEBUG
    
   
#endif
public:
    MusicPlayer(QWidget *parent = nullptr);
    ~MusicPlayer();
    

protected:
    //鼠标按下移动及释放事件
    void mousePressEvent(QMouseEvent* ev)  override;
    void mouseMoveEvent(QMouseEvent* ev) override;
    void mouseReleaseEvent(QMouseEvent* ev) override;


    

private:
    void initTitleBar();
    void initLeftWidgets();
    void initStyleSheet(const QString& file);
    void initBackground();
    //void initSongList();
    void initPlayer();
    //void initTableWidget();
    void initBottomBar();
    void initSearchList();
    void initAll();
    //void setBackground(const QString& fileName);
    //递归开启所有控件的鼠标追踪
    void enableMouseTrackingRecursively(QWidget* widget);
    bool eventFilter(QObject* obj, QEvent* event);

private:
    void region(const QPoint& currentGlobalPoint);
    //获取鼠标相对位置;
    QPoint getMousePos(const QPoint& prev, const QPoint& now);
    //事件
    //图标切换
    void changeEvent(QEvent* event)  override;
    //鼠标双击事件
    void mouseDoubleClickEvent(QMouseEvent* event) override;
    void resizeEvent(QResizeEvent* event) override;
    //bool event(QEvent* e) override;
#ifdef QT_DEBUG
    void onlineMusicTest();
    void KuGouManagerTest();
    void downloadSongTest();
    void initMusicList();
#endif
};
